關於輸出格式前的最後幾個步驟還有 incremental code 的轉格式 incremental_review_markdown_text ,如果判斷屬於 is_incremental ,則提供 sha 值在 url 後方當作 last_commit_url
incremental_review_markdown_text = None
# Add incremental review section
if self.incremental.is_incremental:
last_commit_url = f"{self.git_provider.get_pr_url()}/commits/" \
f"{self.git_provider.incremental.first_new_commit_sha}"
incremental_review_markdown_text = f"Starting from commit {last_commit_url}"
以及將 code review 的結果改成 markdown,這邊有個主要邏輯是遍尋 output_data['review'],根據類型做處理。其中包含
Estimated effort to review: 數值轉換為可視化的藍點和白點
Relevant tests: 有測試的話跟著調整
Security concerns: 如果有安全問題,則會顯示
Can be split: 調用 process_can_be_split,處理 code review 中 Pull Request 是否可以拆分,描述 PR 的主題是否可拆分多個子主題
Key issues to review: 為每個 issue 提供 code 連接
markdown_text = convert_to_markdown_v2(data, self.git_provider.is_supported("gfm_markdown"),
incremental_review_markdown_text, git_provider=self.git_provider)
if 'Estimated effort to review' in key_nice:
key_nice = 'Estimated effort to review'
value = str(value).strip()
if value.isnumeric():
value_int = int(value)
else:
try:
value_int = int(value.split(',')[0])
except ValueError:
continue
blue_bars = '🔵' * value_int
white_bars = '⚪' * (5 - value_int)
value = f"{value_int} {blue_bars}{white_bars}"
if gfm_supported:
markdown_text += f"<tr><td>"
markdown_text += f"{emoji} <strong>{key_nice}</strong>: {value}"
markdown_text += f"</td></tr>\n"
else:
markdown_text += f"### {emoji} {key_nice}: {value}\n\n"
elif 'relevant tests' in key_nice.lower():
value = value.strip().lower()
if gfm_supported:
markdown_text += f"<tr><td>"
if is_value_no(value):
markdown_text += f"{emoji} <strong>No relevant tests</strong>"
else:
markdown_text += f"{emoji} <strong>PR contains tests</strong>"
markdown_text += f"</td></tr>\n"
else:
if is_value_no(value):
markdown_text += f'### {emoji} No relevant tests\n\n'
else:
markdown_text += f"### PR contains tests\n\n"
elif 'security concerns' in key_nice.lower():
if gfm_supported:
markdown_text += f"<tr><td>"
if is_value_no(value):
markdown_text += f"{emoji} <strong>No security concerns identified</strong>"
else:
markdown_text += f"{emoji} <strong>Security concerns</strong><br><br>\n\n"
value = emphasize_header(value.strip())
markdown_text += f"{value}"
markdown_text += f"</td></tr>\n